package com.cls.business.mapper;

import com.cls.business.entity.Notice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 通知公告 Mapper
 *
 * @author weimaomao
 * @date 2020-11-10 09:36:03
 */
@Repository
public interface NoticeMapper extends BaseMapper<Notice> {

    @Select("select  *  from biz_notice where is_publish =1 and modify_time<#{modifyTime} or(modify_time=#{modifyTime} && notice_id < #{noticeId}) order by modify_time desc, notice_id desc  limit  1")
    Notice getPreNotice(@Param("noticeId") Long noticeId, @Param("modifyTime") Date modifyTime);


    @Select("select * from biz_notice where  is_publish =1 and  modify_time>#{modifyTime} or(modify_time=#{modifyTime} && notice_id > #{noticeId})  order by modify_time asc, notice_id desc  limit  1")
    Notice getNextNotice(@Param("noticeId") Long noticeId, @Param("modifyTime") Date modifyTime);

    @Select("select notice.* from biz_notice notice inner join biz_topic_plan plan\n" +
            "on notice.notice_id=plan.select_notice_id\n" +
            "where  curdate()<=plan.select_end_time and is_publish = 1 and notice.type_code = #{typeCode} order by publish_time desc")
    List<Notice> findKtZJValidNotices(@Param("typeCode") String typeCode);
}
